package ed.hbut.supermarket1.service.impl;

import ed.hbut.supermarket1.dto.UpdatePasswordDto;
import ed.hbut.supermarket1.entity.Employee;
import ed.hbut.supermarket1.mapper.EmpMapper;
import ed.hbut.supermarket1.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class EmpServiceImpl implements EmpService {


    @Autowired
    public EmpMapper empMapper;

    @Override
    public List<Employee> getAllEmp() {

        return empMapper.getAllEmp();
    }

    @Override
    public void addEmp(Employee employee) {

        employee.setCreateTime(LocalDateTime.now());
        log.info("employee add employee : {}", employee);
        empMapper.addEmp(employee);

    }

    @Override
    public void updateEmp(Employee employee) {

        empMapper.updateEmp(employee);

    }

    @Override
    public void deleteEmp(int id) {

        empMapper.deleteEmp(id);
 ;
    }

    @Override
    public Employee getById(int id) {


        return empMapper.getById(id);
    }

    @Override
    public String login(String username) {


        return empMapper.login(username);
    }

    @Override
    public Employee getByUsername(String username) {
        return empMapper.getByUsername(username);
    }

    @Override
    public void updatePassword(UpdatePasswordDto updatePasswordDto) {

        empMapper.updatePassword(updatePasswordDto);
    }
}
